// Tabbed pane project template
#include "AesyMoneyLite.hpp"

#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/AbstractPane>
#include <QtCore>
#include "dbadapter.h"
#include "drawchart.h"

using namespace bb::cascades;

AesyMoneyLite::AesyMoneyLite(bb::cascades::Application *app)
: QObject(app)
{
	// create scene document from main.qml asset
	// set parent to created document to ensure it exists for the whole application lifetime
	QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);


	//	    qDebug() << "homepath : " << QDir::homePath();
	//	DBAdapter adapter(QDir::homePath() + "/database");

	qml->setContextProperty("backend", this);
	//	setting.setValue("lang", "zh_cn");

	this->adapter = new DBAdapter(QDir::homePath() + "/database");
	qDebug() << "adapter->InitDb() : " << adapter->InitDb();
	qml->setContextProperty("database", adapter);
	//	qDebug() << "dapter->GetAllPayment : " <<adapter->GetAllPayment(QDateTime(QDate(2013,1,25)), QDateTime(QDate(2013,1,26)), 0);
	//	qDebug() << "dapter->GetPaymentRptGroupByType : " <<adapter->GetPaymentRptGroupByType(QDateTime(QDate(2013,1,1)), QDateTime(QDate(2013,1,30)), 0);
	//	qDebug() << "dapter->GetdayPaymentRpt : " <<adapter->GetdayPaymentRpt(/*QDateTime(QDate(2012,2,1)), */QDateTime(QDate(2013,1,3)), 0);
//	qDebug() << "dapter->Delete : " <<adapter->Delete("t_bas_initialassets", "");

	this->ddrawchart = new DrawChart();
	qml->setContextProperty("draw", ddrawchart);
	//	qDebug() << "QFontDatabase::addApplicationFont : " << QFontDatabase::addApplicationFont(":/arial.ttf");
	//	qDebug() << "QFont::substitutions() : " << QFont::substitutions();
	//	ddrawchart->inputPieChart("fff", "red", 10);
	//	ddrawchart->inputPieChart("ggg", "blue", 20);
	//	ddrawchart->inputPieChart("hhh", "yellow", 30);
	//	ddrawchart->inputPieChart("kkk", "green", 40);
	//	ddrawchart->drawPieChart("ttt");
	//	QList<QVariantMap> ret = adapter.GetPaymentType();
	//	qDebug() << "GetPaymentType : " << ret;
	//	QDir dir(QDir::homePath());
	//	qDebug() << "dir.entryList() : " << dir.entryList();
	//	qDebug() << "setting.value(lang).toString() : " << setting.value("lang").toString();

	// create root object for the UI
	AbstractPane *root = qml->createRootObject<AbstractPane>();
	// set created root object as a scene
	app->setScene(root);
}

QString AesyMoneyLite::getLang()
{
	return setting.value("lang").toString();
}

void AesyMoneyLite::setLang(QString lang)
{
	setting.setValue("lang", lang);
}
